package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.*;
import com.itheima.advantagesup.entity.YddAdvpos;
import com.itheima.advantagesup.service.YddAdvposService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author iTaotao
 * @date 2023/7/27 15:05
 * @desciption: 广告位控制器
 */
@RestController
@RequestMapping("/ydd_advpos")
public class YddAdvposController {
    @Autowired
    private YddAdvposService yddAdvposService;


    /**
     * selete页面
     *
     * @param advposPageDTO advpos页面dto
     * @return {@link R}<{@link PageBean}>
     */
    @GetMapping("/list")
    public R<PageBean> seletePage(AdvposPageDTO advposPageDTO){
        PageBean pageBean = yddAdvposService.seletePage(advposPageDTO);

        return R.success(pageBean);

    }

    /**
     * selete列表
     *
     * @return {@link R}<{@link List}<{@link YddAdvpos}>>
     */
    @GetMapping("/all")
    public R<List<YddAdvpos>> seleteList(){
        List<YddAdvpos> yddAdvposList = yddAdvposService.seleteList();
        return R.success(yddAdvposList);
    }

    /**
     * 添加advpos
     *
     * @param advposCreateDTO advpos创建dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/add")
    public R<?> addAdvpos(@RequestBody AdvposCreateDTO advposCreateDTO){
        yddAdvposService.addAdvpos(advposCreateDTO);
        return R.success();

    }

    /**
     * 删除advpos通过id
     *
     * @param id id
     * @return {@link R}<{@link ?}>
     */
    @GetMapping("/del")
    public R<?> removeAdvposById(Integer id){
        yddAdvposService.removeAdvposById(id);
        return R.success();
    }

    /**
     * selete通过id
     *
     * @param id id
     * @return {@link R}<{@link YddAdvpos}>
     */
    @GetMapping("/rowInfo")
    public R<YddAdvpos> seleteById(String id){
        YddAdvpos yddAdvpos = yddAdvposService.seleteById(id);
        return R.success(yddAdvpos);
    }

    /**
     * 更新advpos
     *
     * @param advposUpdateDTO advpos更新dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> updateAdvpos(@RequestBody AdvposUpdateDTO advposUpdateDTO){
        yddAdvposService.updateAdvpos(advposUpdateDTO);
        return R.success();
    }

}
